<input id="uname" placeholder="请输入要搜索的用户名">
<input  id="btn" type="button" onclick="gogo()" value="搜索" disabled="true">
<input id="username" type="hidden" value="{$username}">
<div id="myDiagramDiv" style="width:100%;height:95%"></div>

<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.8.35/go.js">
</script>
<script>
var uarr=[];
var arr=[];
var x,myDiagram,model;

$(function(){
	var username = $('#username').val();
	if(username == ''){
		username = 'ceshi'
	}
	$.get("teamdata.html",function(d){
		uarr=d;
		$("#btn").removeAttr("disabled");
	});

	x = go.GraphObject.make;
	myDiagram =
	  x(go.Diagram, "myDiagramDiv",
		{
		  initialContentAlignment: go.Spot.Center, // center Diagram contents
		  "undoManager.isEnabled": true, // enable Ctrl-Z to undo and Ctrl-Y to redo
		  layout: x(go.TreeLayout, // specify a Diagram.layout that arranges trees
					{ angle: 90, layerSpacing: 35 })
		});
	 
	// the template we defined earlier
	myDiagram.nodeTemplate =
	  x(go.Node, "Horizontal",
		{ background: "#44CCFF" },
		x(go.TextBlock, "Default Text",
		  { margin: 12, stroke: "white", font: "bold 16px sans-serif" },
		  new go.Binding("text", "name"))
	  );
	 model = x(go.TreeModel);
	 $("#uname").val(username);
	 gogo();
});

function findchild (p) {
	for(var i=0;i<uarr.length;i++)
	{
		if(uarr[i].pid==p)
		{
			arr.push({ "key": uarr[i].id, "parent": uarr[i].pid, "name": uarr[i].username });
			findchild (uarr[i].id);
		}
	}
}
function gogo() 
{
	
	arr=[];

	$(uarr).each(function(i,v){
		if(v.username == $("#uname").val())
		{
			arr.push({ "key": v.id,"name": v.username});
			findchild(v.id);
		}
	});
	model.nodeDataArray =arr;
	myDiagram.model = model;
}
</script>